package ids;

import java.util.HashSet;

public class PortSensor extends Sensor {

	public static int intrusion_port = 911;

	public PortSensor() {
		super();
		this.truePositiveRate = (float) 0.99;
		this.falsePositiveRate = (float) 0.1;
		this.cooperate = true;
	}

	public void compact() {
		this.normalTraces.trimToSize();
		this.intrusionTraces.trimToSize();
	}

	public void reset() {
		this.intrusionTraces.clear();
		this.attackers.clear();
		this.victims.clear();
	}

	@Override
	public void run() {
		this.reset();
		for (int i = 0; i < this.location.allTraces.size(); i++) {
			if (this.location.allTraces.traceAt(i).src_addr.port == intrusion_port) {
				this.intrusionTraces.addTrace(this.location.allTraces
						.traceAt(i));
				this.attackers
						.add(this.location.allTraces.traceAt(i).src_addr.nodeID);
				this.victims
						.add(this.location.allTraces.traceAt(i).dst_addr.nodeID);
			}
		}
	}

	@Override
	public boolean alert() {
		return (this.intrusionTraces.size() > 0);
	}

	@Override
	public HashSet<Integer> getAttackersID() {
		return this.attackers;
	}

	@Override
	public HashSet<Integer> getVictimsID() {
		return this.victims;
	}

	@Override
	public float getScore() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int getNumAttacks() {
		return this.intrusionTraces.size();
	}

	@Override
	public SensorType getSensorType() {
		return SensorType.PortSensor;
	}

}
